package com.wc.codeforces.字符串.Shohag_Loves_Strings;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/11/25 9:37
 * @description
 * https://codeforces.com/contest/2039/problem/B
 */
public class Main {
    /**
     * 思路：
     * 检查满足条件的,
     * aa式的, 是 2 个 a, aa
     * abc式的, 是 6 个, a, b, c, ab, bc, abc
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 300010;
    static char[] cs = new char[N];
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            cs = (" " + sc.next()).toCharArray();
            n = cs.length - 1;
            String s = null;
            for (int i = 1; i < n; i++) {
                if (cs[i] == cs[i + 1]) {
                    s = new String(cs, i, 2);
                    break;
                }
            }
            for (int i = 1; i < n - 1; i++) {
                char a = cs[i], b = cs[i + 1], c = cs[i + 2];
                if (a != b && b != c && a != c) {
                    s = new String(cs, i, 3);
                    break;
                }
            }
            if (s == null) out.println(-1);
            else out.println(s);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

